<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no" />
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>技术论坛</title>
</head>
<style>
.info a,.info-unreviewed a{color:#333;text-decoration:none;}
</style>
<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="../app/index.do"></a>
			</div>
			<div class="header-title">技术论坛</div>
		</div>

	</div>
	<div class="tabs-container">
		<div class="tabs-define">
			<div id="todo" class="active">全部</div>
			<div id="completed">我的</div>
		</div>
	</div>
	<div class="table-container" data-options="region:'center'">
		<div>
			<table id="pro_table" class="easyui-datagrid" style="min-height: 100%">
			</table>

			<div id="pro_tb" class="search-show">
				<div class="search-input">
					<span>查看：</span>
					<span>
						<select id="hightlight" class="easyui-combobox" name="hightlight" style="width: 100%;" editable="false"
							data-options="
							    onSelect: function(rec){
							   		hightlight=rec.value;
							   		if(isnew){
							   			isnew = false;
							   		}else{
							   			refreshProTable();
							   		}
							    },panelHeight: 'auto'">
							<option value="">最新</option>
							<option value="2">精品</option>
						</select>
					</span>
				</div>
				<div class="search-input">
					<span>发布人：</span>
					<span>
						<input id="name" style="width: 100%;" class="easyui-textbox" />
					</span>
				</div>
				<div class="search-input">
					<span>帖子主题：</span>
					<span>
						<input id="title" style="width: 100%;" class="easyui-textbox" />
					</span>
				</div>
				<div class="search-input text-right">
					<a href="#" class="d-btn btn-yellow" id="search">搜索</a>
					<a href="javascript:void(0)" class="d-btn btn-blue" onclick="newpro()">发表新帖</a>
				</div>
			</div>
		</div>
	</div>
</body>
<script>
	var name = "";
	var title = "";
	var hightlight = "";
	var isnew = true;
	$(document).ready(function() {
		all();
		$("#todo").click(function(){
			$(this).siblings().removeClass("active");
			$(this).addClass("active");
			all();
			})
			$("#completed").click(function(){
				$(this).siblings().removeClass("active");
				$(this).addClass("active");
				myforum();
			})
		
	});
	function all(){
		$('#pro_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			toolbar : '#pro_tb',
			url : "../forumPosts",
			method : 'get',
			queryParams : {
				status : 2,
				hightlight : hightlight,
				name : name,
				title : title
			},
			onSelect : function(index,row) {
				currentPro = row;
			},
			columns : [ [ {
				field : 'title',
				title : '帖子主题',
				width : '100%',
				formatter : function(value,row,index) {
					var html='';
					html+= '<div class="info info-mypro"><div onclick="toreply(' + index + ')"><div class="info-item-content" style="width:'+ ellipsis2() +'px;">'+value+'</div>'
					if (row.updatetime == null){
						html+='<div class="info-time">最后发表：' + formatDate(row.createdate) +'</div>'
					}else{
						html+='<div class="info-time">最后发表：' + formatDate(row.updatetime) +'</div>'
					}
					html += '<div class="info-content">回复：'+ row.replycount +'</div></div>'
					if (row.user != null){
						html+= '<div class="info-item text-right"><a href="#" onclick="toperson(' + index + ')">作者：'+row.user.name+'</a></div></div>'
					}
					return html;
				}
			} ] ]
		});
	}
		
	$("#search").click(function() {
		title = $("#title").textbox('getValue');
		name = $("#name").textbox('getValue');
		refreshProTable();
	});
	function refreshProTable() {
		$('#pro_table').datagrid("load", {
			status : 2,
			title : title,
			name : name,
			hightlight : hightlight
		});
	}
	function newpro() {
		window.location.href = "../app/forumadd.do";
	}
	function myforum() {
		$('#pro_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			//toolbar : '#pro_tb',
			url : "../forumPosts",
			method : 'get',
			queryParams : {
				flag : true,
			},
			onSelect : function(index,row) {
				currentPro = row;
			},
			columns : [ [ {
				field : 'title',
				title : '帖子主题',
				width : '',
				formatter : function(value,row,index) {
					var html='';
					html+= '<div class="info-unreviewed has-status"><div onclick="toreply(' + index + ')"><div class="info-item-content" style="width:'+ ellipsis2() +'px;">'+value+'</div>'
					if (row.updatetime == null){
						html+='<div class="info-time">最后发表：' + formatDate(row.createdate) +'</div>'
					}else{
						html+='<div class="info-time">最后发表：' + formatDate(row.updatetime) +'</div>'
					}
					
					if (row.status == 1){
						html+= '<div class="info-status two">未审</div>'
					}else{
						html+= '<div class="info-status ok">已审</div>'
					}
					html += '<div class="info-content">回复：'+ row.replycount +'</div></div>'
					if (row.user != null){
						html+= '<div class="info-item text-right"><a href="#" onclick="toperson(' + index + ')">作者：'+row.user.name+'</a></div></div>'
					}
					return html;
				}
			} ] ]
		});
	}
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear();
		var month = date.getMonth() + 1; //月份是从0开始的
		if (month < 10){
			month = "0" + month;
		}
		var day = date.getDate();
		if (day < 10){
			day = "0" + day;
		}
		var hour = date.getHours();
		if (hour < 10){
			hour = "0" + hour;
		}
		var min = date.getMinutes();
		if (min < 10){
			min = "0" + min;
		}
		var sec = date.getSeconds();
		if (sec < 10){
			sec = "0" + sec;
		}
		var newTime = year + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec;
		return newTime;
	}
	function toreply(index) {
		var item = $("#pro_table").datagrid('getRows')[index];
		window.location.href = "../app/toreply.do?postid=" + item.id;
	}
	function toperson(index) {
		var item = $("#pro_table").datagrid('getRows')[index];
		window.location.href = "../app/toperson.do?userid=" + item.createrid;
	}
	function ellipsis2(){
		var WIDTH = $("body").width();
		var width;
		width = WIDTH-10
		return width;
	}
</script>

</html>